home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pcl4c341.zip / SIMPLE.C < prev    next >
Text File  |  1992-12-24  |  2KB  |  82 lines

  1. /*
  2. **                ---  simple.c ---
  3. **
  4. **  EXAMPLE CODE: This example is meant to be the simpliest
  5. **  possible terminal emulator. Whatever is typed is sent out
  6. **  over the selected serial port, and whatever is received from
  7. **  the serial port is displayed on the screen.
  8. **
  9. **  This example program (not the PCL4C library) is donated to
  10. **  the Public Domain by MarshallSoft Computing, Inc. It is
  11. **  provided as an example of the use of the PCL4C.
  12. **
  13. */
  14.  
  15. #include <stdio.h>
  16. #include "pcl4c.h"
  17.  
  18. #define FALSE 0
  19. #define TRUE !FALSE
  20. #define ESC 0x1b
  21.  
  22. /*** Global Variables ***/
  23.  
  24. int Port = 0;             /* COM port # 0 ( COM1 ) */
  25. int BaudCode = Baud2400;  /* Code for 2400 baud  */
  26. char RxBuf[128];          /* PCL receive buffer  */
  27.  
  28.  
  29. /*** Main ***/
  30.  
  31. main(argc,argv)
  32. int argc;
  33. char *argv[];
  34. {
  35.  char c;
  36.  int i, rc;
  37.  if(argc!=2)
  38.    {printf("Usage: SIMPLE port\n");
  39.     exit(1);
  40.    }
  41.  /* get port number from command line */
  42.  Port = atoi(argv[1]) - 1;
  43.  if((Port<0) || (Port>3))
  44.      {printf("Port must be COM1 to COM4\n");
  45.       exit(1);
  46.      }
  47.  /* setup transmit & receive buffer */
  48.  ErrorCheck( SioRxBuf(Port,RxBuf,Size128) );
  49.  /* set port parmameters */
  50.  ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
  51.  /* reset the port */
  52.  ErrorCheck( SioReset(Port,BaudCode) );
  53.  
  54.  printf("Enter terminal loop ( COM1 @ 2400 Baud )\n");
  55.  printf("Type ESC to quit !\n");
  56.  /* enter terminal loop */
  57.  while(TRUE)
  58.      {/* was key pressed ? */
  59.       if(SioKeyPress())
  60.           {i = SioKeyRead();
  61.            if((char)i==ESC)
  62.               {/* restore COM port status & exit */
  63.                SioDone(Port);
  64.                exit(1);
  65.               }
  66.            else SioPutc(Port,(char)i);
  67.           } /* end if */
  68.       /* any incoming over serial port ? */
  69.       i = SioGetc(Port,0);
  70.       if(i>-1) SioCrtWrite((char)i);
  71.      } /* end while */
  72. } /* end main */
  73.  
  74. int ErrorCheck(Code)
  75. int Code;
  76. {/* trap PCL error codes */
  77.  if(Code<0)
  78.      {SioError(Code);
  79.       SioDone(Code);
  80.       exit(1);
  81.      }
  82. } /* end ErrorCheck */